<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    const obj={};
    /*js中对象的key只能是String类型，使用对象作为key时，会自动调用对象的toString()方法，结果为[object Object]*/
    const obj2={
        name:"张三",
        [obj]:"对象"
    }
    // alert(obj)
    console.log(obj)
    console.log(obj2)


    const obj3 = {name:"张三",age:18};
    const obj4 = {name:"李四",sex:"男"};

    const obj5={...obj3,...obj4};
    console.log(obj5)

    const obj6={...obj4,...obj3};
    console.log(obj6)


    function f1(x,y) {
        /*x的值为null,undefined,false,"",0时，赋值1，否则赋原值*/
        // x = x || 1;
        // y = y || 2;
        /*x的值为null和undefined时，赋值1，否则赋原值*/
        x = x ?? 1;
        y = y ?? 2;
        console.log(x+y)
    }
    f1(0,0);


    function success(res) {
        if(res&&res.code===200){
            console.log(res&&res.data&&res.data.filename)
        }else{
            console.log("参数异常")
        }
    }
    success({code:200,data:{filename:"abc.png"}});
    success();

    function success2(res) {
        if(res?.code===200){
            console.log(res?.data?.filename);
        }else{
            console.log("参数异常")
        }
    }
    success2({code:200,data:{filename:"abc.png"}});
    success2();
</script>
</html>
